/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.econsole.modules.api.controller.ApiTrafficControoler
 * <p>
 * 类产生时间: 2014-11-11 16:28
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 项目组 : 苏州公安移动门户
 * <p>
 * 部门: 手持技术部
 * <p>
 * <p>
 */
package com.oceansoft.mobile.econsole.modules.api.controller;

import com.oceansoft.mobile.econsole.modules.api.entity.Monitor;
import com.oceansoft.mobile.econsole.modules.base.entity.Result;
import com.oceansoft.mobile.econsole.modules.member.entity.Line;
import com.oceansoft.mobile.econsole.modules.member.service.IMemberService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static org.springframework.web.bind.annotation.RequestMethod.*;

/**
 * 交通相关业务控制器
 *
 * @author chenw
 * @time 2014-11-11 16:28
 */
@RestController
@RequestMapping("api/traffic")
public class ApiTrafficController {

    @Resource
    private IMemberService memberService;

    /**
     * 加载指定用户全部自定义线路信息
     *
     * @param userId 用户ID
     * @return Result
     */
    @RequestMapping(value = "lines/{user_id}", method = GET)
    public Result loadAllLines(@PathVariable("user_id") int userId) {
        return memberService.loadCustomLines(userId);
    }

    /**
     * 加载指定线路监控点信息
     *
     * @param lineId 路径Id
     * @return Result
     */
    @RequestMapping(value = "monitors/{line_id}", method = GET)
    public Result loadLineMonitors(@PathVariable("line_id") String lineId) {
        return memberService.loadPathInfo(lineId);
    }

    /**
     * 新增线路信息
     *
     * @return 新增结果
     */
    @RequestMapping(value = "line/add", method = POST)
    public Result addLine(@RequestBody Line line) {
        return memberService.saveLine(line);
    }

    /**
     * 增加自定义线路监控点
     *
     * @param monitor 单个监控点信息
     * @return Result
     */
    @RequestMapping(value = "monitor/add", method = POST)
    public Result addLineMonitor(@RequestBody Monitor monitor) {
        return memberService.saveMonitor(monitor);
    }

    /**
     * 更新线路信息
     *
     * @return Result
     */
    @RequestMapping(value = "monitor/mod", method = POST)
    public Result updateMonitor(Monitor line) {
        return null;
    }

    /**
     * 删除线路信息
     *
     * @param lindId 路线ID
     * @return Result
     */
    @RequestMapping(value = "line/{line_id}", method = DELETE)
    public Result removeLine(@PathVariable("line_id") String lindId) {
        return memberService.removeLine(lindId);
    }

    /**
     * 删除监控点信息
     *
     * @param pk 主键
     * @return Result
     */
    @RequestMapping(value = "monitor/{pk}", method = DELETE)
    public Result delLineMonitor(@PathVariable("pk") int pk) {
        return memberService.delMonitor(pk);
    }
}
